home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16194 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: noc.netcom.net!news
  2. From: Sean Palmer <sean@delta.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Linked lists - will this work?
  5. Date: Tue, 09 Apr 1996 15:50:53 -0400
  6. Organization: deltaComm Development, Inc.
  7. Message-ID: <316ABF9D.27B6@delta.com>
  8. References: <internews46BA23486F@argonet.co.uk>
  9. NNTP-Posting-Host: landspeeder.delta.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 3.0B2 (Win95; I)
  14.  
  15. > If I implemented a new member fn for dllist along the lines of:
  16. > void dllist::iterate(T (*fptr)(T))
  17. > {
  18. > node<T> *temp;
  19. > temp=getstart();
  20. > while(temp)
  21. >     {
  22. >     temp->change(f(temp->getinfo));
  23. >     temp=temp->next;
  24. >     }
  25. > }
  26. > Would that have the effect I require, of taking a function which takes a T
  27. > as its argument and performing that over the list?  If it would do that,
  28. > would it be reasonable 'safe' to use it also for functions that do not
  29. > actually change the data in their body, but return the value passed after,
  30. > say, printing it?
  31.  
  32. No, try:
  33.  
  34. void dllist::iterate(void (*func)(T&)) {
  35.   node<T> *temp=start;
  36.   while(temp) {
  37.     func(temp->data);
  38.     temp=temp->next;
  39.   }
  40. }
  41.